package org.lanqiao.tjut.driver;

import java.io.IOException;
import java.util.Properties;

import javax.sql.DataSource;

import org.apache.commons.dbcp2.BasicDataSource;
import org.apache.commons.dbcp2.BasicDataSourceFactory;

public class DBDataSource {
//数据源对象
	public static DataSource datasource;
	//禁止外部创建该类的实例对象
	private  DBDataSource(){
		
	}
		 public static DataSource getDataSource(){
			 //如果实例对象为Null则进行创建
			 if(datasource==null)
			 {
				 //属性配置文件对象
				 Properties prop=new Properties();
				 
					try {
						prop.load(DBDataSource.class.getClassLoader().getResourceAsStream("db.properties"));
						//获取数据源生成工厂类的静态方法获取数据源数据
						          datasource=BasicDataSourceFactory.createDataSource(prop);
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				
				}
				 
			 
		              return datasource;
		
		
		
	}
	
	
	
	
	
}
